package com.golte.utils;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.stereotype.Component;
import java.util.Date;

/**
 * @Author: sm
 * @version 1.0
 */

@Component
public class JwtUtils {

//    public static final long EXPIRE = 1000*60*30;

    public static final long EXPIRE = 1000*60*120;   // 测试使用 2小时

    public static final  String APP_SECRET = "eEJ34GeDUrOI5GdRr3w";

    public String getToken(String UserCode){
        String token = Jwts.builder()
                .setHeaderParam("typ", "JWT")
                .setHeaderParam("alg", "HS256")
                .setSubject("Golte-token")
                .setIssuedAt(new Date())
                .setExpiration(new Date(System.currentTimeMillis() + EXPIRE))
                .claim("UserCode", UserCode)
                .signWith(SignatureAlgorithm.HS256, APP_SECRET)
                .compact();
        return token;
    }

}
